package b_byteStream;

import org.junit.Test;

import java.io.*;

/*
    缓冲字节输入流 / 缓冲字节输出流
 */
public class BufferedStreamDemo {

    @Test//文件的复制 -> 优化 提升执行效率
    public void test01() throws IOException {
        //缓冲输出流对象
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("aa_copy.txt",true));

        //缓冲输入流对象
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("aa.txt"));

        //文件的复制
        byte[] bs = new byte[1024];
        //记录读取的字节长度
        int len;
        while ((len = bis.read(bs)) != -1){
            bos.write(bs,0,len);
        }

        //手动刷新缓冲区
        //bos.flush();

        //关闭流
        bos.close();


    }
}
